package com.jcfk.eam.service.mould;

import com.jcfk.common.core.utils.BeanUtils;
import com.jcfk.eam.domain.dto.main.EamAssetInfoDTO;
import com.jcfk.eam.domain.dto.mould.MouldWorkRecordDTO;
import com.jcfk.eam.domain.po.main.EamAssetInfo;
import com.jcfk.eam.domain.po.mould.MouldWorkRecord;
import com.jcfk.eam.enums.AssetKind;
import com.jcfk.eam.service.main.EamAssetInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 模具bom详情表
 *
 * @author yrl
 * @email 
 * @date 2024-11-08
 */
@Service
public class MouldMaintainService {

    @Resource
    private EamAssetInfoService eamAssetInfoService;
    @Resource
    private MouldWorkRecordService mouldWorkRecordService;

    @Transactional
    public void maintain(MouldWorkRecordDTO mouldWorkRecordDTO, EamAssetInfoDTO eamAssetInfoDTO) {
        // 保存
        MouldWorkRecord mouldWorkRecord = new MouldWorkRecord();
        BeanUtils.copyProperties(mouldWorkRecordDTO, mouldWorkRecord);
        mouldWorkRecordService.setDefaultValue(mouldWorkRecord);
        mouldWorkRecord.setMouldCode(eamAssetInfoDTO.getAssetCode());
        mouldWorkRecord.setProductCode(eamAssetInfoDTO.getProductCode());
        mouldWorkRecord.setEquipCode(eamAssetInfoDTO.getEquipCode());
        mouldWorkRecord.setProjectCode(eamAssetInfoDTO.getProjectCode());
        mouldWorkRecord.setProcessCode(eamAssetInfoDTO.getProcessCode());
        mouldWorkRecord.setMaterialCode(eamAssetInfoDTO.getMaterialCode());
        mouldWorkRecord.setMaterialId(eamAssetInfoDTO.getMaterialId());
        mouldWorkRecord.setMaterialName(eamAssetInfoDTO.getMaterialName());
        mouldWorkRecord.setMaterialGroup(eamAssetInfoDTO.getAssetTypeCode());
        mouldWorkRecord.setAssetKind(AssetKind.MOULD.getValue());
        mouldWorkRecord.setWorkKind("9");
        mouldWorkRecord.setEnabled("1");
        mouldWorkRecordService.save(mouldWorkRecord);
        // 保存
        eamAssetInfoDTO.setAssetStatus(mouldWorkRecordDTO.getAssetStatus());
        EamAssetInfo eamAssetInfo = new EamAssetInfo();
        BeanUtils.copyProperties(eamAssetInfoDTO, eamAssetInfo);
        eamAssetInfoService.updateById(eamAssetInfo);
    }
}

